<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src='jquery-1.10.2.min.js'> </script>
<head>
<style type = 'text/css'>
.ClassDiv{
  background-color:yellow;
  width:100px;
  height:100px;
  border: solid 2px #F00;
  float:left;
}
</style>
</head>
<script>
function board(){
var num = prompt('nhap mot so: ');
n = true;
a = 1;
b = 2;
id1 = '';
id2 = '';
for(i = 1;i<=num;i++){
 
document.write('<div class = "ClassDiv" id = "the'+i+'" align = "center" >'+i+'</div>');

}
for(j = 1;j<=num;j++)
{
$('#the'+j).click(function(){
 alert(j);
 if( n == true)
 {a = $(this).text();
 a = parseInt(a);
 id1 = "#the"+j;
 n=!n;

 }
 else{
  b = $(this).text();
  b = parseInt(b);
  a = a+b;
   id2 = "#the"+j;
  b = a -b;
  a = a - b;
  n=!n;
 }
  //alert(id1+" va "+id2 + "voi "+n);
});
}
}
board();
</script>